﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
	{
		HttpFileCollection files = Request.Files;
        string orderNo = Request["no"];
		if (files.Count == 0)
		{
			Response.Write("请勿直接访问本文件");
			Response.End();
		}

        string path = Server.MapPath("images/product/");

		// 只取第 1 个文件
		HttpPostedFile file = files[0];

		if (file != null && file.ContentLength > 0)
		{
			// flash 会自动发送文件名到 Request.Form["fileName"]
            //string savePath = path + "/" + Request.Form["fileName"];
            Hongapo_Common.ImageHelper.CreateFolder(path + DateTime.Now.ToString("yyMMdd") + "/");
            string smallFileName = DateTime.Now.ToString("yyMMdd") + "/s_" + DateTime.Now.ToString("ffff") + Request["fileName"];
            string maxFileName = DateTime.Now.ToString("yyMMdd") + "/m_" + DateTime.Now.ToString("ffff") + Request["fileName"];
            Hongapo_Common.ImageHelper.SendToSmallImage(file.InputStream, 110, 110, path, smallFileName);
            Hongapo_Common.ImageHelper.SendToSmallImage(file.InputStream, 470, 470, path, maxFileName);
            Hongapo_Model.Product.ProductImage model = new Hongapo_Model.Product.ProductImage();
            Hongapo_Services.Product.ProductImage bll = new Hongapo_Services.Product.ProductImage();
            model.BigImg = maxFileName;
            model.Isopen = 0;
            model.OrderNo = orderNo;
            model.Remark = "";
            model.SmallImg = smallFileName;
            bll.Add(model);

		}
    }
}
